package com.shop2cn.iapi.agentproducts.testcase;

import com.google.gson.JsonArray;
import com.shop2cn.iapi.agentproducts.parameter.BrandListBean;
import com.shop2cn.iapi.agentproducts.service.BrandListCall;
import com.ymatou.iapi.dglogin.service.SellerRegisterCall;
import com.ymatou.iapi.godmch.parameter.createmchBean;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.DGUserCallService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;

import org.junit.*;
import org.junit.experimental.categories.Category;

/**
*品牌列表
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_BrandList{
	private static BrandListBean brandlistBean;
	private static BrandListCall brandlistCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("品牌列表");
	}

	@Before
	public void caseUp() {
		brandlistBean=new BrandListBean();
		brandlistCall=new BrandListCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(brandlistCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_BrandList_01() {//业务校验
		Logger.start(true,"获取品牌列表");
		//依赖suggestbizer.ymatou.com
		try {
			SellerRegisterCall dfseller = DGUserCallService.regDefSellerRegister();
			String accessToken=dfseller.getString("accessToken");
			Integer mchid=Integer.valueOf(dfseller.getString("userId"));
			createmchBean createmchbean2 = GodmchManageCallService.InitcreatemchBeanForChannel(mchid);
			GodmchManageCallService.createmchCallForChannel(createmchbean2);
			String keyWord = "Burberry";
			brandlistBean.setKeyWord(keyWord);
			brandlistCall.setData(brandlistBean);
			brandlistCall.addHeader("ymt-pars","accesstoken="+accessToken);
			brandlistCall.callService();
			//{"brandList":[{"brandId":10089,"brandName":"Burberry"}]}
			JsonArray ja = brandlistCall.getJsonObject().get("brandList").getAsJsonArray();
			Logger.verifyEquals(true,ja.size()>0,"验证返回");
			Logger.verifyEquals("Burberry",ja.get(0).getAsJsonObject()
					.get("brandName").getAsString(),"验证brandName");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}